<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>174-事件阻止行为-输入框只能输入数字.html</title>
</head>
<body>
	输入数字<input type="text" id="txt">
</body>
<script>
	var oTxt = document.getElementById('txt');
	oTxt.onkeydown = function(ev){
		console.log(ev.keyCode);
		if((ev.keyCode < 48 || ev.keyCode > 57) &&ev.keyCode != 8 && ev.keyCode !=37 && ev.keyCode !=39){
			return false;
		}
	}
</script>
</html>